package my.software.utility;

public final class FloatUtil {

	/**
	 * @param numberString
	 *            the string to be parsed.
	 * @return an Float object holding the value represented by the string
	 *         argument if the string cannot be parsed as an float; Otherwise,
	 *         return null.
	 */
	static public Float valueOf(String numberString) {
	    Float floatNumber = null;
		if (null != numberString) {
			try {
				floatNumber = Float.valueOf(numberString);
			} catch (NumberFormatException numberFormatException) {
				floatNumber = null; // Default if can't parse to Float.
			}
		}
		return floatNumber;
	}

	/**
	 * @param numberString
	 *            a String containing the double representation to be parsed.
	 * @return The Float value represented by the argument in decimal if the
	 *         string contain a parsable float; Otherwise, return null.
	 */
	static public float parseFloat(String numberString) {
		float floatNumber = 0;
		if (null != numberString) {
			try {
				floatNumber = Float.parseFloat(numberString);
			} catch (NumberFormatException numberFormatException) {
				floatNumber = 0; // Default if can't parse to float.
			}
		}
		return floatNumber;
	}

	/**
	 * Prevent constructor.
	 */
	private FloatUtil() {
	}

}
